package org.at;

import java.math.BigDecimal;

// 顾客类
public class Customer {
    // 顾客名字
    private String name;
    // 购物车
    private ShoppingCart shoppingCart;

    public Customer(String name) {
        this.name = name;
        this.shoppingCart = new ShoppingCart();
    }

    public String getName() {
        return name;
    }

    public ShoppingCart getShoppingCart() {
        return shoppingCart;
    }

    public void buyFruit(Fruit fruit, int weight) {
        shoppingCart.addFruit(fruit, weight);
    }

    /**
     * 结账
     */
    public BigDecimal checkout(String code) {
        BigDecimal discountedTotal = shoppingCart.calculateDiscountedTotalPrice(code);
        shoppingCart.clear();
        return discountedTotal;
    }

}
